package campeonatofutebol.activity;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.view.View;
import campeonatofutebol.util.*;

public class TableList extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		List<String> tableRowStrings = new ArrayList<String>();
//		setContentView(R.layout.table_list_layout);
//		//Open a document from a valid URL using jsoup
//		Document doc = null;
//		try {
//			doc = Jsoup.connect("http://esporte.uol.com.br/futebol/campeonatos/brasileiro/2012/serie-a/classificacao/classificacao.htm").get();
//			
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//
//		//Once this document has loaded, select all <tr> tableRow elements into tableRows, with each
//		//tableRow, collect all children, which will be <td>, into tableDatas Elements, test that Elements class for text,
//		//if text exists, transfer the text of these children to a string, test that string for a substring, 
//		//In this case, a date, if it contains this substring, add it to the created tableRowStrings ArrayList.
//		//This function falsely returns a string with duplicated table row information.
//
//		//Example Test Criteria, in reality this may be interfaced to a datetime or textbox widget
//		//to facilitate an end-user defined search
//		
//
//		//select all <tr> or Table Row Elements
//		Elements tableRows = doc.select(".gameTable tr"); // recupera da tabela .gameTable todos os <tr>
//
//		//Load ArrayList with table row strings
//		for (Element tableRow : tableRows){
//
//			if (tableRow.hasText()){
//				String rowData = tableRow.text();
//				//if(rowData.contains(testString)){
//					tableRowStrings.add(rowData);
//				//}
//
//			}
//
//		} 
		tableRowStrings = Config.recuperaDadosHtml(Constantes.UOL_TAB_SERIEB, Constantes.BUSCA_TIMES);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, tableRowStrings);
		setListAdapter(adapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		String item = (String) getListAdapter().getItem(position);
		Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
	}



}
